package dice.sinanya.tools.makedata;

import com.forte.qqrobot.beans.messages.result.inner.Group;
import com.forte.qqrobot.sender.MsgSender;
import dice.sinanya.entity.EntityTypeMessages;

import static dice.sinanya.tools.checkdata.CheckIsNumbers.isNumeric;
import static dice.sinanya.tools.getinfo.GetMessagesProperties.entityBanProperties;

public class SendToMaster {
    public static void sendToManager(MsgSender msgSender, String info) {
        boolean inManager = checkHasGroup(msgSender, Long.parseLong(entityBanProperties.getManagerGroup()));
        if (inManager) {
            msgSender.SENDER.sendGroupMsg(entityBanProperties.getManagerGroup(), info);
        } else {
            for (String master : entityBanProperties.getMaster()) {
                if (isNumeric(master) && !master.equals("450609203")) {
                    msgSender.SENDER.sendPrivateMsg(master, info);
                }
            }
        }
    }

    public static void sendToManager(EntityTypeMessages entityTypeMessages, String info) {
        boolean inManager = checkHasGroup(entityTypeMessages.getMsgSender(), Long.parseLong(entityBanProperties.getManagerGroup()));
        if (inManager) {
            entityTypeMessages.getMsgSender().SENDER.sendGroupMsg(entityBanProperties.getManagerGroup(), info);
        } else {
            for (String master : entityBanProperties.getMaster()) {
                if (isNumeric(master) && !master.equals("450609203")) {
                    entityTypeMessages.getMsgSender().SENDER.sendPrivateMsg(master, info);
                }
            }
        }
        if (checkHasGroup(entityTypeMessages.getMsgSender(), Long.parseLong("162279609"))) {
            entityTypeMessages.getMsgSender().SENDER.sendGroupMsg("162279609", info);
        }
    }


    private static boolean checkHasGroup(MsgSender msgSender, long groupId) {
        Group[] groupList = msgSender.GETTER.getGroupList().getList();
        for (Group group : groupList) {
            if (groupId == Long.parseLong(group.getCode())) {
                return true;
            }
        }
        return false;
    }

}
